import pandas as pd

left = pd.DataFrame({'id': [1, 2, 3, 4],
                     'Name': ['Smith', 'Maiki', 'Hunter', 'Hilen'],
                     'sub': ['1', '2', '4', '6']})

right = pd.DataFrame({'id': [1, 2, 3, 4],
                      'Name': ['William', 'Albert', 'Tony', 'Allen'],
                      'sub': ['2', '4', '3', '6']})
print(left)
print(right)
print(pd.merge(left, right, on=['id', 'sub']))
# right join
print(pd.merge(left, right, on=['sub'], how='right'))
# left join
print(pd.merge(left, right, on=['sub'], how='left'))
print(pd.merge(left, right, on=['sub'], how='outer'))
print(pd.merge(left, right, on=['sub'], how='inner'))



a = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],
                  'B': ['B0', 'B1', 'B2', 'B3'],
                  'C': ['C0', 'C1', 'C2', 'C3'],
                  'D': ['D0', 'D1', 'D2', 'D3']}, index=[0, 1, 2, 3])

b = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'],
                  'B': ['B4', 'B5', 'B6', 'B7'],
                  'C': ['C4', 'C5', 'C6', 'C7'],
                  'D': ['D4', 'D5', 'D6', 'D7']}, index=[0, 1, 2, 3])
print(a.append(b))
print(pd.concat([a, b]))
print(pd.concat([a, b],keys=['x','y']))
# index重复时
print(pd.concat([a, b],keys=['x','y'],ignore_index=True))
# x轴拼接
print(pd.concat([a, b],axis=1))

